//
//  CodeViewController.m
//  Project_IOS
//
//  Created by Jeff on 2022/1/18.
//

#import "CodeViewController.h"
#import "CodeNumberView.h"
#import "ResetPWViewController.h"
#import <Masonry/Masonry.h>
#import "Color.h"
@interface CodeViewController ()
@property (nonatomic, strong) UILabel *phoneLb;

@property (nonatomic, strong) CodeNumberView *numberView;

@end

@implementation CodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleStr = @"输入验证码";
    self.buttonView.btnStr = @"确认";
    
    [self.contentView addSubview:self.phoneLb];
    [self.phoneLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(97);
        make.centerX.mas_equalTo(0);
    }];
    
    self.numberView = [[CodeNumberView alloc] init];
    
    [self.contentView addSubview:self.numberView];
    [self.numberView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(131);
        make.centerX.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(311, 52));
    }];
    
    [self.contentView addSubview:self.buttonView];
    [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(311, 48));
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(self.numberView.mas_bottom).offset(30);
    }];
    
    [self.buttonView.button addTarget:self action:@selector(loginBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    self.buttonView.avable = true;
    
    UILabel *underlineLabel = [[UILabel alloc] init];
    underlineLabel.font = [UIFont systemFontOfSize:12];
    NSString *textStr = @"已有账号？登录";
    underlineLabel.textColor = [Color colorWithHexString:@"#999999"];
    // 下划线
    //注意: NSStrikethroughStyleAttributeName 是添加中划线,这时textStr如果是中文字符则没有效果
    NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSUnderlineColorAttributeName : [Color colorWithHexString:@"#2075FD"],NSForegroundColorAttributeName:[Color colorWithHexString:@"#2075FD"]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr];
    [attribtStr addAttributes:attribtDic range:NSMakeRange(5, 2)];
    //赋值
    underlineLabel.attributedText = attribtStr;
    
    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelClick)];
    
    [underlineLabel addGestureRecognizer:gestureRecognizer];
    underlineLabel.userInteractionEnabled = YES;
    
    [self.contentView addSubview:underlineLabel];
    [underlineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.buttonView.mas_bottom).offset(30);
            make.centerX.mas_equalTo(0);
    }];
    
    
    [self.numberView startCount:60];
}

- (void)labelClick {
    [self.navigationController popViewControllerAnimated:true];
}

- (void)loginBtnOnClick {
//    [MobClick event:@"CodeClick"];
    [self.navigationController pushViewController:[[ResetPWViewController alloc] init] animated:true];
}


- (UILabel *)phoneLb {
    if (!_phoneLb) {
        _phoneLb = [[UILabel alloc] init];
        _phoneLb.font = [UIFont systemFontOfSize:14];
        _phoneLb.textColor = [Color colorWithHexString:@"#999999"];
    }
    return _phoneLb;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
